package il.ac.braude.sona.IcmUnitTest;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;

public class StatisticsFromData {

	
	StaticsGenericCalculator statics;
	private HashMap<String,String> data;
	double[] values;
	
	public StatisticsFromData(HashMap<String,String> data){
		this.data=new HashMap<String,String>(data);
		values = new double[data.size()];
		initDataToStatistics();
	}

	private void initDataToStatistics() {
		int i = 0;
	 	Set<Entry<String, String>> reportData = data.entrySet();
			Iterator<Entry<String, String>> mapitarator = reportData.iterator(); 

			while (mapitarator.hasNext())
			{
				Entry<String, String> map = mapitarator.next();
	    	    values[i++] = Double.parseDouble(map.getValue()); 
	    	}
			statics = new StaticsGenericCalculator(values);
		
	}
	
	public boolean checkStd(double stdToCheck){
		double check=(double)Math.round(statics.getStdDev()*1000)/1000;
		if (Double.compare(check, (double)Math.round(stdToCheck*1000)/1000)==0)
			return true;
		return false;
	}
	
	public boolean checkMedian(double medianToCheck){
		if (statics.median()==medianToCheck)
			return true;
		return false;
	}
}
